<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%--
  Created by IntelliJ IDEA.
  User: 董灌磊
  Date: 2024/4/16
  Time: 8:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/webjars/layui/2.6.8/css/layui.css">
    <script src="/webjars/layui/2.6.8/layui.js"></script>
</head>
<body>
<div class="layui-container">
    <div class="layui-form" id="searchForm" lay-filter="searchForm">
        <div class="layui-inline">
            <label class="layui-form-label">业主姓名:</label>
            <div class="layui-input-inline">
                <input type="text" name="ownername" placeholder="输入业主名称" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">业主身份证:</label>
            <div class="layui-input-inline">
                <input type="text" name="ownercard" placeholder="输入业主身份证号" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">业主手机号:</label>
            <div class="layui-input-inline">
                <input type="text" name="ownerphone" placeholder="输入业主手机号" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">小区名:</label>
            <div class="layui-input-block">
                <select name="plotid" id="plotids">
                    <option value="0">请选择小区</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn" onclick="search()" >查询</button>
        </div>
        <div class="layui-inline">
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <table id="ownerTable" lay-filter="ownerTables"  class="layui-table layui-table-hover"></table>
</div>
<script>
    let $=layui.$
    $.get("/property/plot/show")
        .then(({data})=>{
            console.log(data);
            //data:数组
            $(data).each(function (i,e){
                let option = $("<option value='"+e.id+"'>"+e.plotname+"</option>");
                $("[name=plotid]").append(option);
            });
            //重新渲染下拉列表
            layui.form.render('select');
        });
    layui.use(function (){
        let table=layui.table;
        table.render({
            id:"one",
            elem:"#ownerTable",
            url:"/owner/all",
            toolbar: "#headTool",
            page:true,
            cols:[[
                {field:'number',align: 'center',type:'numbers',title:"编号"},
                {field:'id',align: 'center',hide:true,title:"序号"},
                {field:'ownername',align: 'center',title:"业主姓名"},
                {field:'ownerpwd',align: 'center',title:"业主密码"},
                {field:'ownercardno',align: 'center',title:"业主身份证号"},
                {field:'ownerphone',align: 'center',title:"业主手机号"},
                {field:'ownersex',align: 'center',title:"业主性别"},
                {field:'plotid',align: 'center',title:"所属小区",templet(d){
                    return d.plot.plotname;
                    }},
            ]]
        })
    })
    //点击去查询
    function search(){
        //获取表单的值,表单序列化
        var where = layui.form.val('searchForm');
        console.log(where)
        //条件查询，重载表格因为键和值都是where，所以可以值保留键
        layui.table.reload('one',{where});
    }
    //点击添加
    function add(){
        layui.layer.open({
            type : 1,
            title : "提示",
            area:["500px","400px"],
            content: $("#add"),
            icon : 3,
            btn:["确定","取消"],
            yes(){
                //通过表单序列化，获取输入的内容
                let addForm = layui.form.val("addForm");
                console.log(addForm);
                //发送ajax请求
                $.post("/park/addpark",addForm)
                    .then(({msg})=>{
                        //关闭弹出层
                        layui.layer.close(layui.layer.index);
                        //弹出消息提示框
                        layui.layer.msg(msg);
                        //刷新表格
                        layui.table.reload('one');
                    });
            }
        });
    }
</script>

</body>
</html>
